<?php

class tarifasM extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    //I N S E R T 

    public function guardarTarifas($categoria, $data) {
        //procesamos los datos
        foreach ($data as $d => $k) {
            $value = explode("-", "$d");
            if ($value[0] == "tarifa") {
                $query = "DELETE FROM tarifa_x_persona WHERE id_temporada='$value[2]' AND id_categoria='$categoria' AND n_personas='$value[1]'";
                $this->db->query($query);
                $query = "INSERT INTO tarifa_x_persona(id_temporada,id_categoria,n_personas,valor) VALUES('$value[2]','$categoria','$value[1]','$k') ";
                $this->db->query($query);
            } else if ($value[0] == "dia") {
                $query = "UPDATE categoria_x_temporada SET {$value[1]} ='{$k}'  WHERE id_categoria='$categoria' AND id_temporada='$value[2]'";
                //  echo $query;
                $this->db->query($query);
            }
        }
    }

    // S E L E C T    
    public function getCategoriaTemporada($categoria) {
        $query = "SELECT * FROM categoria_x_temporada WHERE id_categoria='$categoria' ORDER BY id_temporada";
        return $this->db->query($query)->result();
    }

    public function getTarifaPersona($categoria) {
        $query = "SELECT * FROM tarifa_x_persona WHERE id_categoria='$categoria' ORDER BY id_temporada";
        return $this->db->query($query)->result();
    }

    public function getSimbolo($establecimiento) {
        $query = "SELECT lm.* FROM lista_moneda lm,establecimiento e WHERE e.id_establecimiento='$establecimiento' and lm.id_moneda=e.moneda";
        return $this->db->query($query)->result();
    }

}